#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <arguments.h>

void createDoS(fNum* h_U,long hits)
{
  int e,j;
  long RN = hits;
  fNum *Re = (fNum*)malloc(sizeof(fNum) * RN);
  memset(Re,0,sizeof(fNum) * RN);
  fNum T0,T1,T2;
  for(e=0;e<RN;e+=1)
  {
    fNum Temp=0;
    fNum x=(fNum) (e-RN/2) / RN * 2;
    for(j=0;j<N;j++)
    {
      if(j==0)
      {
        T0 = 1;
        Temp = T0;
      }
      else if(j==1)
      {
        T1=x;
        Temp = T1;
      }
      else
      {
        T2 = 2 * x * T1 - T0;
        Temp=T2;
        T0=T1;
        T1=T2;
      }
      fNum kernel =
             (fNum)1/(N + 1)*((N-j+1)*cos(PI*j/(N+1))
                           + sin(PI*j/(N+1))*cos(PI/(N+1))/sin(PI/(N+1)));
      Re[e] += h_U[j] * kernel* Temp;
    }
  }

  FILE* file = fopen("result.dat","wb");
  fwrite(Re,sizeof(fNum),RN,file);
  fclose(file);
}
